/**
 * 下一次点击在时间内就不会被重新计数，比如手机打开调试模式的多次点击
 * @param func
 * @param count
 * @param timeOut
 * @constructor
 */
function NextClickInTime<T extends Function>(func: T, count: number = 2, timeOut: number = 200): T {
  let clickNumber = 0
  let timeOutEr = null
  // @ts-ignore
  return function (...args) {
    if (timeOutEr) {
      clearTimeout(timeOutEr)
    }
    if (clickNumber === count) {
      clickNumber = 0
      clearTimeout(timeOutEr)
      func.apply(this, args)
      return
    }
    clickNumber++
    timeOutEr = setTimeout(() => {
      clickNumber = 0
      clearTimeout(timeOutEr)
    }, timeOut)
  };
}

export default NextClickInTime
